package list;

import javax.swing.event.AncestorEvent;

public class AdjacencyList extends DList {

	private int degree;
	
	/**
	 * AdjacencyList constructor
	 */
	public AdjacencyList() {
		head = newNode(null, null, null, null);
		head.next = head;
		head.prev = head;
		size = 0;
	}
	
	/**
	 * Creates a new AdjacencyListNode
	 * @param item is the item to store in the node
	 * @param list is the list it belongs to
	 * @param prev is the previous node
	 * @param next is the next node
	 * @return a new AdjacencyListNode
	 */
	protected AdjacencyListNode newNode(Object item, AdjacencyList list,
			AdjacencyListNode prev, AdjacencyListNode next) {
		return new AdjacencyListNode(item, list, prev, next);
	}
	
	/**
	 * sets the degree of an AdjacencyList
	 * @param degree is the number of degrees that a vertex might have
	 */
	public void setDegree(int degree) {
		this.degree = degree;
	}
	
	/**
	 * gets the degree of AdjacencyList
	 * @return the degree of the AdjacencyList
	 */
	public int getDegree() {
		return degree;
	}
	
	/**
	 * inserts an AdjacencyListNode in the front of this AdjacencyList
	 */
	public void insertFront(Object item) {
		AdjacencyListNode aHead = (AdjacencyListNode) head;
		AdjacencyListNode aNext = (AdjacencyListNode) head.next; 
		AdjacencyListNode node = newNode(item, this, aHead, 
				aNext);
		head.next.prev = node;
		head.next = node;
		size++;
	}
}
